翻訳と辞書
Words near each other
・ Friends & Lovers
・ Friends & Lovers (film)
・ Friends & Lovers (Marsha Ambrosius album)
・ Friends & People
・ Friends & Relatives
・ Friends & Strangers
・ Friends 'Til the End
・ Friends 'Til the End (book)
・ Friends (1799 ship)
・ Friends (1912 film)
・ Friends (1938 film)
・ Friends (1971 film)
・ Friend a Soldier
・ Friend and Foe
・ Friend class
Friend function
・ Friend Humphrey
・ Friend Humphrey House
・ Friend Like Me
・ Friend Like That
・ Friend Me
・ Friend of a friend
・ Friend of a Friend (song)
・ Friend of Dorothy
・ Friend of History Award
・ Friend of Mannequin
・ Friend of Mine
・ Friend of Mine (Greg Brown album)
・ Friend of Mine (Kelly Price song)
・ Friend of Mine (Treble Charger song)


Dictionary Lists
翻訳と辞書 辞書検索 [ 開発暫定版 ]
スポンサード リンク

Friend function : ウィキペディア英語版
Friend function
In object-oriented programming, a friend function that is a "friend" of a given class is allowed access to private and protected data in that class that it would not normally be able to as if the data was public.


Normally, a function that is defined outside of a class cannot access such information. Declaring a function a friend of a class allows this, in languages where the concept is supported.
A friend function is declared by the class that is granting access, explicitly stating what function from a class is allowed access. A similar concept is that of friend class.
Friends should be used with caution. Too many functions or external classes declared as friends of a class with protected or private data may lessen the value of encapsulation of separate classes in object-oriented programming and may indicate a problem in the overall architecture design. Generally though, friend functions are a good thing for encapsulation, as you can keep data of a class private from all except those who you explicitly state need it, but this does mean your classes will become tightly coupled.
==Use cases==
This approach may be used in friendly function when a function needs to access private data in objects from two different classes.
This may be accomplished in two similar ways
*a function of global or namespace scope may be declared as friend of both classes
*a member function of one class may be declared as friend of another one.

#include
using namespace std;

class Foo; // Forward declaration of class Foo in order for example to compile.
class Bar ;

class Foo ;

// Definition of a member function of Bar; this member is a friend of Foo
void Bar::show(Bar& x, Foo& y)

// Friend for Bar and Foo, definition of global function
void show(Bar& x, Foo& y)

int main()


抄文引用元・出典: フリー百科事典『 ウィキペディア(Wikipedia)
ウィキペディアで「Friend function」の詳細全文を読む



スポンサード リンク
翻訳と辞書 : 翻訳のためのインターネットリソース

Copyright(C) kotoba.ne.jp 1997-2016. All Rights Reserved.